package com.dbqn.zhao.service.impl;

import com.dbqn.zhao.entity.Novel;
import com.dbqn.zhao.entity.User;
import com.dbqn.zhao.service.BaseService;
import com.dbqn.zhao.service.UserService;
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.List;
import java.util.Scanner;

public class GetNovelsServiceImpl implements BaseService {

    Scanner sc=new Scanner(System.in);

    @Override
    public List execute(List list) {
        System.out.println("---------------------------言情小说列表开始------------------------");
        System.out.println("序号\t名称\t作者\t简介");

        for (int i = 0; i < list.size(); i++) {

            Novel novel1=(Novel) list.get(i);
            System.out.println((i+1)+novel1.getBookname()+"\t"+novel1.getName()+"\t"+novel1.getJianjie());
        }
        System.out.println("---------------------------小说列表结束------------------------");
        System.out.println("0.返回上一级菜单");
        System.out.println("-1.返回上一级菜单");
        System.out.println("请输入小说序号阅读");
        int shuuru=sc.nextInt();

        if(shuuru==0){
            return null;
        }else if(shuuru==-1){

            System.out.println("请输入小说名称:");
            String bookname=sc.next();
            System.out.println("请输入作者:");
            String name=sc.next();
            System.out.println("请输入简介:");
            String jianjie=sc.next();
          for(;;){

              System.out.println("请输入上传的txt(请注意路径用/或\\):");
              String luj=sc.next();

              File file=new File(luj);


                  if(!file.exists()){
                      System.out.println("路径不存在，请重新上传");
                      continue;
                  }


              Novel nover3=new Novel();
              nover3.setBookname(bookname);
              nover3.setName(name);
              nover3.setJianjie(jianjie);

              list.add(nover3);
              System.out.println("添加成功！");
              for (int i = 0; i < list.size(); i++) {

                  Novel novel1=(Novel) list.get(i);
                  System.out.println((i+1)+novel1.getBookname()+"\t"+novel1.getName()+"\t"+novel1.getJianjie());
              }
              System.out.println("************************");
              System.out.println("0.返回上一级菜单");
              System.out.println("1.继续上传");
              int xz=sc.nextInt();
              if(xz==0){
                 return null;
              }else{
                  continue;
              }

          }


        }

        FileReader reader2= null;
        try {
            reader2 = new FileReader("F:\\天气.txt");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

        char[] chars2=new char[1024];
        String s2="";
        int date2=0;
        while (true){

            try {
                date2= reader2.read(chars2);
            } catch (IOException e) {
                e.printStackTrace();
            }finally {
                try {
                    reader2.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            if(date2==-1){
                break;
            }else{
                s2=s2+new String(chars2,0,date2);
                System.out.println(s2);
                break;
            }
        }

        return list;
    }

}